/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.persistence;

import br.ufmg.dees.insane.assembler.Assembler;
import br.ufmg.dees.insane.assembler.FemAssembler;

/** A class representing Solver
 * @author CENOURA!!!
 * @since 14/08/2005
 */
public class Solver_XSD {
    
	static long startTime = System.currentTimeMillis();
	static long endTime = System.currentTimeMillis();
	
	
    public static void main(String[] args) {
        String fileName;
		if(args.length != 0){
			fileName = args[0];
		}
		else{
			System.out.println("Informe o nome de arquivo de entrada\n");
			fileName = Teclado.lerString();
			fileName = fileName.trim();
		}
		PersistenceAsXML_XSD p = new PersistenceAsXML_XSD();
		PersistenceAsInsane o = new PersistenceAsInsane();
        p.fillInsaneFromFile(fileName+".xml");
        if(p.getSolution().getClass().getName().equals("br.ufmg.dees.insane.solution.EquilibriumPath")){
            PersistenceAsTable t = new PersistenceAsTable();
            t.setModel(p.getModel());
            t.setSolution(p.getSolution());
            t.getSolution().setLabel(fileName);
            t.fillInsaneFromFile(fileName+".xml");
//            p.getModel().addObserver(t);
            ConsoleNonLinearWriter c = new ConsoleNonLinearWriter();
            p.getSolution().addObserver(c);
        }
        Assembler a = new FemAssembler();
        a.setModel(p.getModel());
        
        p.getModel().addObserver(p);
        p.getModel().addObserver(o);
        p.getSolution().setLabel(fileName);
        p.getSolution().setAssembler(a);
        
        o.setModel(p.getModel());
        o.setSolution(p.getSolution());

        startTime = System.currentTimeMillis();
        p.getSolution().execute();
		long dif = (endTime - startTime);
		System.out.println();
		System.out.println("Time: "+dif+" miliseconds");
       
    }
}